﻿using System;

namespace TimeProject.WebSite.ViewModels
{
    public class MessageContainer
    {
        public bool Flag1 { set; get; }
        public bool Flag2 { set; get; }

        /// <summary>
        /// The message.
        /// </summary>
        public string Text { set; get; }

        /// <summary>
        /// True if this MessageContainer contains error messages.
        /// </summary>
        public bool ContainsErrors { set; get; }

        /// <summary>
        /// True if this MessageContainer contais notification messages.
        /// </summary>
        public bool ContainsNotifications { set; get; }

        /// <summary>
        /// Resets the MessageContainer.
        /// </summary>
        public void Reset()
        {
            if (Flag1)
            {
                Flag1 = false;
                Flag2 = true;
            }
            else
            {
                Flag1 = true;
                Flag2 = false;
            }

            Text = null;
            ContainsErrors = false;
            ContainsNotifications = false;
        }

        /// <summary>
        /// Adds an error message to this MessageContainer.
        /// </summary>
        /// <param name="text">The message text.</param>
        public void AddErrorMessage(string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            AddMessage(text);
            ContainsErrors = true;
            ContainsNotifications = false;
        }

        /// <summary>
        /// Adds a notification message to this MessageContainer.
        /// </summary>
        /// <param name="text">The message text.</param>
        public void AddNofificationMessage(string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            AddMessage(text);
            ContainsErrors = false;
            ContainsNotifications = true;
        }

        private void AddMessage(string text)
        {
            if (Text == null)
            {
                Text = text;
            }
            else
            {
                Text = Text + Environment.NewLine + text;
            }
        }

    }
}